from django.db import models
from utils.BaseModel import BaseModel


# Create your models here.
class CateModel(BaseModel):
    name = models.CharField(max_length=32, verbose_name='课程分类名称')
    parent = models.ForeignKey("self", on_delete=models.CASCADE, verbose_name='父级分类', related_name="son")
    recommend = models.BooleanField(default=False, verbose_name='是否推荐')
    is_hot = models.BooleanField(default=False, verbose_name='是否热门')
    is_good = models.BooleanField(default=False, verbose_name='是否精品')

    class Meta:
        db_table = 'fgcate'

    def __str__(self):
        return self.name


class TeacherModel(BaseModel):
    name = models.CharField(max_length=30, verbose_name="老师名称")
    image = models.CharField(max_length=200, verbose_name="老师头像")
    jobtitle = models.CharField(max_length=30, verbose_name="老师职称")
    intro = models.TextField(verbose_name="老师简介")
    sales = models.IntegerField(verbose_name="销量")

    class Meta:
        db_table = 'fg2teacher'

    def _str__(self):
        return self.name


class CourseModel(BaseModel):
    name = models.CharField(max_length=30, verbose_name="课程名称")
    image = models.CharField(max_length=200, verbose_name="课程图片")
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name="课程价格")
    category = models.ForeignKey(CateModel, on_delete=models.CASCADE, verbose_name="课程分类")
    teacher = models.ForeignKey(TeacherModel, on_delete=models.CASCADE, verbose_name="授课老师")
    intro = models.TextField(verbose_name="课程简介")
    level = models.CharField(max_length=30, verbose_name="课程难度", choices=((0, '初级'), (1, '中级'), (2, '高级')), default=0)
    numbers = models.IntegerField(verbose_name="课程人数")
    is_home = models.BooleanField(default=True, verbose_name='是否推荐')
    video = models.CharField(max_length=200, verbose_name='视频', default='http://127.0.0.1:8000/uploads/course/video/1.MP4')

    class Meta:
        db_table = 'fgcourse'

    def str_(self):
        return self.name
